import {  PrismaClient,users_chat_list_ucl_type } from "../generated/prisma/default";
import  User  from "../router/model/m_user";
import  Video  from "../router/model/m_video";
import  m_users_chat_list  from "../router/model/m_users_chat_list";
import  m_ai_chat_list  from "../router/model/m_ai_chat_list";


export type tableType=User|Video|m_users_chat_list|m_ai_chat_list;

export class BaseRepository<T extends tableType> {
 private  static  prisma: PrismaClient;
 static{
    if(!this.prisma)
    BaseRepository.prisma= new PrismaClient();

   //  this.prisma.users.create({
     
   //  })
 }
  private model:('users'|'users_chat_list'|'videos'|'ai_chat_list');

  constructor( model:('users'|'users_chat_list'|'videos'|'ai_chat_list')) {
    this.model = model;
  }

  // 创建记录
  async create(data: T) {

     //@ts-ignore
    return await BaseRepository.prisma[this.model  ].create({data });
    
  }

  // 根据 ID 查询
  async findById(id: number) {
     //@ts-ignore
    return await BaseRepository.prisma[this.model].findUnique({ where: { id } });
  }

  // 查询所有
  async findAll(params?: any) {
     //@ts-ignore
    return await BaseRepository.prisma[this.model].findMany(params);
  }

  // 更新记录
  async update(id: number, data: T) {
     //@ts-ignore
    return await BaseRepository.prisma[this.model].update({ where: { id }, data });
  }

  // 删除记录
  async delete(id: number) {
     //@ts-ignore
    return await BaseRepository.prisma[this.model].delete({ where: { id } });
  }
}
